package com.example.whatrubbish.controller;

import com.example.whatrubbish.service.MenuService;
import com.example.whatrubbish.utils.Constants;
import com.example.whatrubbish.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@CrossOrigin
@Controller
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    MenuService menuService;

    @ResponseBody
    @RequestMapping(value = "/selectAll")
    public JsonResult selectAll(){
        JsonResult jsonResult;
        try{
            List list = menuService.selectAll();
            jsonResult = new JsonResult(Constants.STATUS_SUCCESS, "success", list);
        }catch (Exception e){
            jsonResult = new JsonResult(Constants.STATUS_ERROR, "error");
        }
        return jsonResult;
    }
}
